<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<%@include file="/views/common/include/taglib.jsp"%>
<%@include file="/views/common/include/head.jsp"%>
<title>Insert title here</title>
<link rel="stylesheet" href="${ctx}/css/page/reset.css" type="text/css">
<link rel="stylesheet" href="${ctx}/css/page/zhifu.css" type="text/css">
<style type="text/css">
    .alisubmit {
        width:400px;
        height:40px;
        border:0;
        background-color:#0ae;
        font-size:16px;
        color:#FFF;
        cursor:pointer;
        margin-top:80px
    }
</style>
<script type="text/javascript">
    var ctx = '${ctx}';
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    $(function(){
        $(".ul-wrap li").click(function(){
            var index=$(this).index();
            $(this).css("background-color","#E3E3E3").siblings().css("background-color","#fff");
            $(".tabcontent").eq(index).show().siblings().hide();
        })
        
        if('' != $('#orderNumber').val()) {
            var orderNumber = $('#orderNumber').val();
            var type = $('#type').val();
            var url = '${ctx}' + '/pay/payCode?orderNumber=' + orderNumber + '&type=' + type;
            $('#QRCode').attr('src', url);
            
            var payResult = false;
            window.setInterval(function(){ 
                checkResult(); 
            }, 3000); 
        }
        
        $('.alisubmit').click(function(){
            $.ajax({
                type: "POST",
                url: ctx + '/pay/aliPay',
                dataType : 'json',
                data:{
                    type : $('#type').val(),
                    outTradeNo : $('#orderNumber').val()
                },
                success: function(data){
                    window.parent.aliPay(data.sHtmlText);
                    parent.layer.close(index);
                },
                error: function(res){
                }
            });
        })
    });
    var doing = false;
    function checkResult(){
        if(!doing){
            doing = true;
            var orderNumber = $('#orderNumber').val();
            var type = $('#type').val();
            $.ajax({
                type : "GET",
                url : ctx + "/pay/wxPayResult?orderNumber=" + orderNumber + '&type=' + type,
                cache : false,
                dataType : 'json',
                success : function(data) {
                    if (data.success) {
                        layer.msg("支付成功", {
                            icon : 1,
                            time : 2000
                        });
                        window.parent.wxPay();
                        parent.layer.close(index);
                    } else {
                       // alert(data.msg);
                    }
                    doing = false;
                }
            });
        }
    }

</script>
</head>
<body>
    <input type="hidden" value="${payInfo.tradeNo}" id="orderNumber" />
    <input type="hidden" value="${payInfo.type}" id="type" />
    <div>
        <div class="wrap-box">
            <div class="top-box">
                <div class="fl">
                    <span >订单编号：</span><span>${payInfo.tradeNo}</span>
                </div>
                <div class="fr">
                    <span >金额：</span><span class="title">￥${payInfo.totalFee}</span>
                </div>
            </div>
            <div class="tab-box-wrap">
               <div class="tab-wrap">
                    <ul class="ul-wrap">
                        <li class="tabhover">微信</li>
                        <li>支付宝</li>
                    </ul>
               </div>
               <div>
                    <div class="tabcontent">
                        <img id="QRCode" width="230px">
                        <img src="${ctx}/images/qrdd/paytip.png">
                    </div>
                    <div class="tabcontent" style="display: none">
                        <input type="button" class="alisubmit" value ="确认支付">
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>